package com.cn.book.socketdemo4;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        MulticastSocket socket = new MulticastSocket(10086);
        socket.joinGroup(InetAddress.getByName("224.0.1.0"));//加入组播地址

        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
        socket.receive(packet);

        byte[] data = packet.getData();
        int length = packet.getLength();
        System.out.println(new String(data, 0, length));

        socket.close();
    }
}
